import { createBrowserRouter } from "react-router-dom";
import Layout from "@/pages/Layout";
import Login from "@/pages/Login";
import App from "@/App";
import AuthRoute from "@/components/AuthRoute";
const token = localStorage.getItem("token");

function ExistToken() {
	return (
		<AuthRoute>
			<Login />
		</AuthRoute>
	);
}

const router = createBrowserRouter([
	{
		path: "",
		element: (
			<App>
				<AuthRoute>
					<Layout />
				</AuthRoute>
			</App>
		),
		children: [
			{
				// 默认
				index: true,
				element: <div>首页</div>,
			},
			{
				path: "article",
				element: <div>文章管理</div>,
			},
			{
				path: "publish",
				element: <div>创建文章</div>,
			},
		],
	},
	{
		path: "login",
		element: <App>{token ? <ExistToken /> : <Login />}</App>,
	},
]);

export default router;
